<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.huawei.iptvmw.epg.bean.info.UserProfile" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@include file="util/getData.jsp" %>
<%@include file="util/getData.jsp" %>
<%@include file="util/getData.jsp" %>
<%@include file="util/getData.jsp" %>
<%@include file="util/getData.jsp" %>
<%@include file="util/getData.jsp" %>
<%@include file="util/getData.jsp" %>
<%
<%
    UserProfile profile = new UserProfile(request);
    String userId = profile.getUserId();
    String groupId = profile.getUserGroupId();
    String stbId = profile.getStbId(); //STBID
    String stbIp = profile.getStbIp();
//String industryData = getReturnData("http://172.17.102.200:8082/jyBizMgr/bizServer/getAccountStartAndEpg?account="+userId, "GET", null);
    String industryData = getReturnData("http://172.17.102.200:8082/jyBizAuth2/bizServer/getAccountStartAndEpg?account=" + userId+"&boxId="+stbId+"&ip="+stbIp, "GET", null);
    String path = request.getRequestURI().substring(0, request.getRequestURI().lastIndexOf("/") + 1);
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
    int areaId = profile.getAreaId();
    String user_group_id = profile.getUserGroupId();
    Date date = new Date();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    String tempDate = formatter.format(date);
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>贵州</title>
    <style type="text/css">
        body {
            background-color: #000
        }
    </style>
    <script type="text/javascript" src="js/webxiri_1.0.6.js"></script>
    <script type="text/javascript" src="js/lifePlatform.js?v=1.0.0.0"></script>
    <script type="text/javascript">
      var curDate = "<%=tempDate%>";
      var userId = "<%=userId%>";
      var stbIp = "<%=stbIp%>";
      var stbId = "<%=stbId%>";
      var areaId = "<%=areaId%>";
      var path = "<%=path%>";
      var basePath = "<%=basePath%>";
      var user_group_id = "<%=user_group_id%>";
      Authentication.CTCSetConfig('userId', userId);
      Authentication.CTCSetConfig('user_group', user_group_id);
      Authentication.CTCSetConfig('stbIp', stbIp);
      Authentication.CTCSetConfig('stbId', stbId);
      Authentication.CTCSetConfig('platform', "yd2");
      var industryData =<%=industryData%>;
      if (industryData&&industryData.identityAuth){
          Authentication.CTCSetConfig('identityAuth', industryData.identityAuth);
      }else{
          Authentication.CTCSetConfig('identityAuth', 0);
      }
      function turnOnYuyin(group) {
        var oFz = {
          "12" : "ls",
          "16" : "hgy",
          "17" : "qx",
          "21" : "tz",
          "22" : "tzi",
          "24" : "sd",
          "25" : "hx",
          "27" : "gsh",
          "29" : "zy",
          "30" : "cg",
          "31" : "ld",
          "32" : "bj",
          "34" : "lz",
        };
        var _name = oFz[Authentication.CTCGetConfig('UserGroupNMB')]
        if (_name) {
          Authentication.CTCSetConfig("cityCs", _name);
        } else {
          Authentication.CTCSetConfig("cityCs", "-1");
        }
        if (industryData == null || industryData == "null") {
          onloadxiri();
          jumpByGroup(group,function (){
              window.location.href = "page/layout.html?R=" + Math.random();
          });
          return
        }
        var resultCode = industryData.resultCode || "";
        if (resultCode == "000000") {
          if (industryData.useStatus == 1) {
            onloadxiri();
            jumpByGroup(group,function (){
                window.location.href = "page/layout.html?R=" + Math.random();
            });
          } else if (industryData.useStatus == 0) {
            window.location.href = "page/error.html?error=0";
          } else if (industryData.useStatus == 2) {
            window.location.href = "page/error.html?error=2";
          } else if (industryData.useStatus == 3) {
            window.location.href = "page/error.html?error=3";
          } else if (industryData.useStatus == 4) {
            window.location.href = "page/error.html?error=4";
          } else if (industryData.useStatus == 5) {
            window.location.href = "page/error.html?error=5";
          } else {
            window.location.href = "page/error.html?error=7";
          }
        } else if (industryData == null || industryData == "null") {
          jumpByGroup(group,function (){
              window.location.href = "page/layout.html?R=" + Math.random();
          });
        } else {
          window.location.href = "page/error.html?error=8&resultCode=" + resultCode;
        }
      }

      function onloadxiri() {
        if(curDate == "20200404" || curDate == "20200403"){
          return;
        }
        var sence = getScence();
        //此处是回调函数 command对应sence中的command的key，例如command['_PLAY'] = ["$P(_PLAY)"];，那么回调中intent.._command的值就为_PLAY
        var callback = function(intent) {
        };
        //同步客户端信息
        var clientInfo = {};
        clientInfo['basePath'] = "<%=basePath%>";
        var channelInfo = {}
        //同步客户端信息
        var listener = new Xiri.Listener(callback);
        listener.regist(sence);
        listener.syncChannelInfo(channelInfo);
        listener.syncClientInfo(clientInfo);
      }

      function getScence() {
        var sence = {};
        var command = {};
        var feedback = {};
        sence['_scene'] = "com.iflytek.xiri.MyScene";
        sence['_feedbacks'] = feedback;
        sence['_commands'] = command;
        return sence;
      }
      function beginInit(group){
          try {
              // 查询杭研接口
              function getHyGroup(cb,group){
                  try {
                      lifePlat({
                          "adid":'483',
                          "success" : function(res){
                              if(typeof(res.ids) != "undefined" && res.ids.length>0){
                                  setLoc(res.ids[0]);
                              }else{
                                  setLoc("-1");
                              }
                          },
                          "error": function(res){
                              setLoc("-3");
                          }
                      });
                  } catch (error) {
                      setLoc("-4");
                  }
                  //
                  function setLoc(id){
                      Authentication.CTCSetConfig('HYGROUP',id);
                      // sessionStorage.setItem("hygroup",id);
                      cb(group);
                  }
              }
              getHyGroup(turnOnYuyin,group);
          } catch (error) {
              turnOnYuyin(group);
          }
      }

      // turnOnYuyin();

      function crmInfo(userId,cb) {
          try {
              var xhr = new XMLHttpRequest();
              xhr.open('GET',
                  "http://117.187.220.2:8000/behavior/crmUser/getGroupByAccount?account=" + userId, true);
              var timer = setTimeout(function () {
                  cb(-1);
                  xhr.abort();
                  xhr = null;
                  return;
              }, 2000);
              xhr.onload = function () {
                  if (xhr.readyState == 4 && xhr.status == 200) {
                      clearTimeout(timer);
                      try {
                          var crmData = JSON.parse(xhr.responseText);
                          if (crmData && crmData.result && crmData.result.groupMap && crmData.result.groupMap.epgBootDiversion) {
                              if (crmData.result.groupMap.epgBootDiversion[0]) {
                                  cb(crmData.result.groupMap.epgBootDiversion[0]);
                              } else {
                                  cb(-1);
                              }
                          } else {
                              cb(-1);
                          }
                      } catch (e) {
                          cb(-1);
                      }
                  }
              };
              xhr.send();
              xhr.onerror = function () {
                  cb(-1);
              }
          }catch (e) {
              cb(-1);
          }
      }

      function jumpByGroup(group,cb){
          switch (group) {
              case 38:
                  window.location.href ='../../v6groupa/en/vue/index.html?r='+Math.random();
                  break;
              case 39:
                  window.location.href = '../../v6groupa/en/vuerelease/index.html?r='+Math.random();
                  break;
              case 40:
                  window.location.href = '../../v6groupa/en/vuedev/index.html?r='+Math.random();
                  break;
              case 41:
                  window.location.href = '../../v6groupa/en/jinji/index.html?r='+Math.random();
                  break;
              case 42:
                  window.location.href = '../../v6groupb/en/page/layout.html?r='+Math.random();//v2现网
                  break;
              case 43:
                  window.location.href = '../../yfb/en/page/layout.html?r='+Math.random();//v2预发布
                  break;
              case 44:
                  window.location.href = '../../default03/en/page/layout.html?r='+Math.random();//v2测试
                  break;
              default:
                  cb();
                  break;
          }
      }
    </script>
</head>
<body onLoad="crmInfo(userId,beginInit);">
</body>
</html>
